package com.ycu.jk16.mall.util.common;

public class PageUtil {
	/** 当前页码 */
	private int pageIndex;
	/** 每页显示的数量 */
	private int pageSize;
	/** 总记录条数 */
	private int recordCount;
	/** 请求URL page?pageIndex={0} */
	private String submitUrl;
	/** 定义总页数 */
	private int totalPage;

	public PageUtil() {
		super();
	}

	public PageUtil(int pageIndex, int pageSize, int recordCount) {
		super();
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.recordCount = recordCount;

		totalPage = recordCount % pageSize == 0 ? recordCount / pageSize : recordCount / pageSize + 1;
	}

	// 判断是否是首页
	public boolean isFirstPage(int pageIndex) {
		return pageIndex == 1;
	}

	// 判断是否是尾页
	public boolean isLastPage(int pageIndex) {
		return pageIndex == getTotalPage();
	}

	// 判断是否有前页
	public boolean hasPreviousPage(int pageIndex) {
		return pageIndex > 1;
	}

	// 判断是否有下一页
	public boolean hasNextPage(int pageIndex) {
		return pageIndex < getTotalPage();
	}

	/* getters and setters */
	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}

	public String getSubmitUrl() {
		return submitUrl;
	}

	public void setSubmitUrl(String submitUrl) {
		this.submitUrl = submitUrl;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

}
